package com.toweave.starter.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.toweave.starter.R;
import com.toweave.starter.beans.UserBean;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

public class ResponseActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_response);

        TextView btn_response = findViewById(R.id.btn_response);
        btn_response.setOnClickListener(this);

        TextView tv_response_desc = findViewById(R.id.tv_response_desc);

        Bundle bundle = getIntent().getExtras();

        // 接收消息
        String request_time = bundle.getString("request_time");
        String request_content = bundle.getString("request_content");
        String desc = String.format("request_time: %s, request_content: %s", request_time, request_content);
        tv_response_desc.setText(desc);

        String[] request_str_list = bundle.getStringArray("request_str_list");
        Log.d("-liz-37", Arrays.toString(request_str_list));

        ArrayList<String> strArrayList = bundle.getStringArrayList("request_str_array_list");
        Log.d("-liz-40", Objects.requireNonNull(strArrayList).toString());

        // UserBean user = new UserBean(0, "name1", "code1");
        UserBean user = (UserBean) bundle.getSerializable("request_user_serializable");
        Log.d("-liz-45", user.toString());

        ArrayList<UserBean> userBeanArrayList = bundle.getParcelableArrayList("userBeanArrayListKey");
        Log.d("-liz-45", userBeanArrayList.toString());
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, RequestActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("response_time", "123");
        bundle.putString("response_content", "ABC");
        intent.putExtras(bundle);
        setResult(Activity.RESULT_OK, intent);
        finish();
        // switch (v.getId()) {
        //     case R.id.btn_response:
        //         break;
        // }
    }
}